package com.server.service;

import com.server.Untils.MybatisClass;
import com.server.entity.ExpenseRecord;
import com.server.example.ExpenseRecordExample;
import com.server.mapper.ExpenseRecordMapper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author Admin
 */
public class ExpenseRecordService {

    /**
     * 得到消费记录/得到所有用户的消费记录
     * 调用方法 new ExpenseRecordService().getList(list)
     * @param userList 当我传输的 userList 为空时候(得到消费记录)，不为空时候(得到所有用户的消费记录)
     * @return 得到消费记录/得到所有用户的消费记录
     */
    public List<ExpenseRecord> getList(List<Integer> userList){
        SqlSession sqlSession = MybatisClass.getSqlSession();
        ExpenseRecordMapper expenseRecordMapper = sqlSession.getMapper(ExpenseRecordMapper.class);
        ExpenseRecordExample expenseRecordExample = new ExpenseRecordExample();
        if (userList.size() > 0) {
            expenseRecordExample.createCriteria().andUserIdIn(userList);
        }else {
            expenseRecordExample.createCriteria().andIdIsNotNull();
        }
        List< ExpenseRecord> expenseRecordList = expenseRecordMapper.selectByExample(expenseRecordExample);
        sqlSession.close();
        return expenseRecordList;
    }
}
